import actors.Actor
import com.jediflasher.game_server.util.log.Logger
import java.io._
import java.net.{SocketException, Socket}

/**
 * User: Obi
 * Date: 11.07.11
 * Time: 22:53
 */

class SocketPolicyHandler(socket: Socket) extends Actor {

	private val policyFileResponse =
		"<?xml version=\"1.0\"?>"+
  		"<cross-domain-policy>"+
  		"<allow-access-from domain=\"*\" to-ports=\"*\" />"+
  		"</cross-domain-policy>";


	private val out = new DataOutputStream(socket.getOutputStream);
	private val in = new DataInputStream(socket.getInputStream);

	def act() {
		Logger.log("policy file request:::");
		try {
			var str:String = "";
			while((str = in.readUTF()) != null){
				Logger.log("policy request: "+str);
				out.writeUTF(policyFileResponse + "\0");
				Logger.log("policy file sent");
				socket.close();
				this.exit();
			}
		}
		catch {
			case e: SocketException => System.err.println(e);
			case e: IOException => System.err.println(e.getMessage);
			case e => System.err.println("Unknown error " + e);
		}
	}
}